package jsyf.oa.web.system;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.User2RightFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2017/12/7 0007.
 */

@Api(value = "用户菜单接口", description = "用户菜单接口")
@Controller
@RequestMapping("/user2Right")
public class User2RightController {

    @Resource
    private User2RightFacade user2RightFacade;

    @RequestMapping(value = "/config.json", method = RequestMethod.POST)
    public void config(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        Boolean result = user2RightFacade.config(jsonParam.getString("userId"), jsonParam.getString("rightIds"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(String.valueOf(result)));
    }

    @RequestMapping(value = "/getByUserId.json", method = RequestMethod.POST)
    public void getByUserId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> result = user2RightFacade.getByUserId(jsonParam.getString("userId"));
        ResponseUtils.putJsonResponse(response,BaseUtils.succsessArrRespond(result));
    }

}
